package Algorithm.DoublePointer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Solution {
    public int smallestDifference(int[] a, int[] b) {
        Arrays.sort(a);
        Arrays.sort(b);
        long min = Integer.MAX_VALUE;

        int i=0;
        int j=0;
        while(i<a.length&&j<b.length){
            long delta = a[i] - b[j];
            if(min>Math.abs(delta)){
                min = Math.abs(delta);
            }

            if(a[i]<b[j]){
                i++;
            }else{
                j++;
            }
        }

        return (int)min;

    }
}

public class MainClass {
    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for(int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[] a = stringToIntegerArray(line);
            line = in.readLine();
            int[] b = stringToIntegerArray(line);

            int ret = new Solution().smallestDifference(a, b);

            String out = String.valueOf(ret);

            System.out.print(out);
        }
    }
}
